package org.dromara.datacheck.service.impl.jd;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.utils.MapstructUtils;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.datacheck.domain.bo.jd.JdOtherOutWarehouseOrderBo;
import org.dromara.datacheck.domain.jd.JdOtherOutWarehouseOrder;
import org.dromara.datacheck.domain.vo.jd.JdOtherOutWarehouseOrderVo;
import org.dromara.datacheck.mapper.jd.JdOtherOutWarehouseOrderMapper;
import org.dromara.datacheck.service.jd.IJdOtherOutWarehouseOrderService;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * 金蝶-其他出库单Service业务层处理
 *
 * @author 刘武贵
 * @date 2024-09-08
 */
@RequiredArgsConstructor
@Service
public class JdOtherOutWarehouseOrderServiceImpl implements IJdOtherOutWarehouseOrderService {

    private final JdOtherOutWarehouseOrderMapper baseMapper;


    /**
     * 查询金蝶-其他出库单
     *
     * @param id 主键
     * @return 金蝶-其他出库单
     */
    @Override
    public JdOtherOutWarehouseOrderVo queryById(Long id){
        return baseMapper.selectVoById(id);
    }

    /**
     * 分页查询金蝶-其他出库单列表
     *
     * @param bo        查询条件
     * @param pageQuery 分页参数
     * @return 金蝶-其他出库单分页列表
     */
    @Override
    public TableDataInfo<JdOtherOutWarehouseOrderVo> queryPageList(JdOtherOutWarehouseOrderBo bo, PageQuery pageQuery) {
        LambdaQueryWrapper<JdOtherOutWarehouseOrder> lqw = buildQueryWrapper(bo);
        Page<JdOtherOutWarehouseOrderVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
        return TableDataInfo.build(result);
    }

    /**
     * 查询符合条件的金蝶-其他出库单列表
     *
     * @param bo 查询条件
     * @return 金蝶-其他出库单列表
     */
    @Override
    public List<JdOtherOutWarehouseOrderVo> queryList(JdOtherOutWarehouseOrderBo bo) {
        LambdaQueryWrapper<JdOtherOutWarehouseOrder> lqw = buildQueryWrapper(bo);
        return baseMapper.selectVoList(lqw);
    }

    /**
     * 构建查询包装器
     *
     * @param bo 业务对象，包含查询参数
     * @return LambdaQueryWrapper 查询包装器
     */
    private LambdaQueryWrapper<JdOtherOutWarehouseOrder> buildQueryWrapper(JdOtherOutWarehouseOrderBo bo) {
        // 获取查询参数中的自定义参数
        Map<String, Object> params = bo.getParams();

        // 创建LambdaQueryWrapper实例，用于组装查询条件
        LambdaQueryWrapper<JdOtherOutWarehouseOrder> lqw = Wrappers.lambdaQuery();

        // 添加库存方向的精确查询条件
        lqw.eq(StringUtils.isNotBlank(bo.getInventoryDirection()), JdOtherOutWarehouseOrder::getInventoryDirection, bo.getInventoryDirection());

        // 添加订单状态的精确查询条件
        lqw.eq(StringUtils.isNotBlank(bo.getJdOtherOutWarehouseOrderStatus()), JdOtherOutWarehouseOrder::getJdOtherOutWarehouseOrderStatus, bo.getJdOtherOutWarehouseOrderStatus());

        // 添加订单号的精确查询条件
        lqw.eq(StringUtils.isNotBlank(bo.getJdOtherOutWarehouseOrderNumber()), JdOtherOutWarehouseOrder::getJdOtherOutWarehouseOrderNumber, bo.getJdOtherOutWarehouseOrderNumber());

        // 添加客户名称的精确查询条件
        lqw.eq(StringUtils.isNotBlank(bo.getJdOtherOutWarehouseOrderCustomer()), JdOtherOutWarehouseOrder::getJdOtherOutWarehouseOrderCustomer, bo.getJdOtherOutWarehouseOrderCustomer());

        // 添加物料编码的精确查询条件
        lqw.eq(StringUtils.isNotBlank(bo.getMaterialCode()), JdOtherOutWarehouseOrder::getMaterialCode, bo.getMaterialCode());

        // 添加物料名称的模糊查询条件
        lqw.like(StringUtils.isNotBlank(bo.getMaterialName()), JdOtherOutWarehouseOrder::getMaterialName, bo.getMaterialName());

        // 添加单位名称的模糊查询条件
        lqw.like(StringUtils.isNotBlank(bo.getUnitName()), JdOtherOutWarehouseOrder::getUnitName, bo.getUnitName());

        // 添加发货仓库的精确查询条件
        lqw.eq(StringUtils.isNotBlank(bo.getDeliverGoodsWarehouse()), JdOtherOutWarehouseOrder::getDeliverGoodsWarehouse, bo.getDeliverGoodsWarehouse());
        lqw.eq(bo.getNewOrderDate() != null, JdOtherOutWarehouseOrder::getNewOrderDate, bo.getNewOrderDate());
        lqw.eq(bo.getActualDeliveryNumber() != null, JdOtherOutWarehouseOrder::getActualDeliveryNumber, bo.getActualDeliveryNumber());
        if (params.get("beginTime") != null && params.get("endTime") != null) {
            lqw.between(JdOtherOutWarehouseOrder::getNewOrderDate,
                params.get("beginTime"),
                params.get("endTime"));
        }
        // 返回构建好的查询包装器
        return lqw;
    }


    /**
     * 新增金蝶-其他出库单
     *
     * @param bo 金蝶-其他出库单
     * @return 是否新增成功
     */
    @Override
    public Boolean insertByBo(JdOtherOutWarehouseOrderBo bo) {
        JdOtherOutWarehouseOrder add = MapstructUtils.convert(bo, JdOtherOutWarehouseOrder.class);
        validEntityBeforeSave(add);
        boolean flag = baseMapper.insert(add) > 0;
        if (flag) {
            bo.setId(String.valueOf(add.getId()));
        }
        return flag;
    }

    /**
     * 修改金蝶-其他出库单
     *
     * @param bo 金蝶-其他出库单
     * @return 是否修改成功
     */
    @Override
    public Boolean updateByBo(JdOtherOutWarehouseOrderBo bo) {
        JdOtherOutWarehouseOrder update = MapstructUtils.convert(bo, JdOtherOutWarehouseOrder.class);
        validEntityBeforeSave(update);
        return baseMapper.updateById(update) > 0;
    }

    /**
     * 保存前的数据校验
     */
    private void validEntityBeforeSave(JdOtherOutWarehouseOrder entity){
        //TODO 做一些数据校验,如唯一约束
    }

    /**
     * 校验并批量删除金蝶-其他出库单信息
     *
     * @param ids     待删除的主键集合
     * @param isValid 是否进行有效性校验
     * @return 是否删除成功
     */
    @Override
    public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
        if(isValid){
            //TODO 做一些业务上的校验,判断是否需要校验
        }
        return baseMapper.deleteByIds(ids) > 0;
    }

    /**
     * 查询金蝶-其他出库单列表所有数据
     *
     * @return 金蝶-其他出库单列表
     */
    @Override
    public List<JdOtherOutWarehouseOrder> queryAll() {
        return baseMapper.selectList(null);
    }

    /**
     * 清空金蝶-直接调拨单列表所有数据
     *
     * @return 金蝶-直接调拨单列表
     */
    @Override
    public Integer deleteAll() {
        return baseMapper.delete(new QueryWrapper<>());
    }

    /**
     * 查询金蝶-其他出库单列表
     * 场景分类：部门领料-网红达人店
     * 业务查询条件：根据jd_other_out_warhouse_order_customer客户为网红达人查询
     *
     * @param bo
     * @param pageQuery
     */
    @Override
    public TableDataInfo<JdOtherOutWarehouseOrderVo> queryPageListByCustomer1(JdOtherOutWarehouseOrderBo bo, PageQuery pageQuery) {
        LambdaQueryWrapper<JdOtherOutWarehouseOrder> lqw = buildQueryWrapperByCustomer1(bo);
        Page<JdOtherOutWarehouseOrderVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
        return TableDataInfo.build(result);
    }

    /**
     * 构建查询包装器
     * 场景分类：部门领料-网红达人店
     * 业务查询条件：根据jd_other_out_warehouse_order_customer客户为网红达人查询
     *
     * @param bo 业务对象，包含查询参数
     * @return LambdaQueryWrapper 查询包装器
     */
    private LambdaQueryWrapper<JdOtherOutWarehouseOrder> buildQueryWrapperByCustomer1(JdOtherOutWarehouseOrderBo bo) {
        // 获取查询参数中的自定义参数
        Map<String, Object> params = bo.getParams();

        // 创建LambdaQueryWrapper实例，用于组装查询条件
        LambdaQueryWrapper<JdOtherOutWarehouseOrder> lqw = Wrappers.lambdaQuery();

        // 添加库存方向的精确查询条件
        lqw.eq(StringUtils.isNotBlank(bo.getInventoryDirection()), JdOtherOutWarehouseOrder::getInventoryDirection, bo.getInventoryDirection());

        // 添加订单状态的精确查询条件
        lqw.eq(StringUtils.isNotBlank(bo.getJdOtherOutWarehouseOrderStatus()), JdOtherOutWarehouseOrder::getJdOtherOutWarehouseOrderStatus, bo.getJdOtherOutWarehouseOrderStatus());

        // 添加订单号的精确查询条件
        lqw.eq(StringUtils.isNotBlank(bo.getJdOtherOutWarehouseOrderNumber()), JdOtherOutWarehouseOrder::getJdOtherOutWarehouseOrderNumber, bo.getJdOtherOutWarehouseOrderNumber());

        // 添加客户名称的精确查询条件
        lqw.eq(StringUtils.isNotBlank(bo.getJdOtherOutWarehouseOrderCustomer()), JdOtherOutWarehouseOrder::getJdOtherOutWarehouseOrderCustomer, bo.getJdOtherOutWarehouseOrderCustomer());

        // 添加物料编码的精确查询条件
        lqw.eq(StringUtils.isNotBlank(bo.getMaterialCode()), JdOtherOutWarehouseOrder::getMaterialCode, bo.getMaterialCode());

        // 添加物料名称的模糊查询条件
        lqw.like(StringUtils.isNotBlank(bo.getMaterialName()), JdOtherOutWarehouseOrder::getMaterialName, bo.getMaterialName());

        // 添加单位名称的模糊查询条件
        lqw.like(StringUtils.isNotBlank(bo.getUnitName()), JdOtherOutWarehouseOrder::getUnitName, bo.getUnitName());

        // 添加发货仓库的精确查询条件
        lqw.eq(StringUtils.isNotBlank(bo.getDeliverGoodsWarehouse()), JdOtherOutWarehouseOrder::getDeliverGoodsWarehouse, bo.getDeliverGoodsWarehouse());

        // 客户
        lqw.in(CollUtil.isNotEmpty(bo.getJdOtherOutWarehouseOrderCustomerList()), JdOtherOutWarehouseOrder::getJdOtherOutWarehouseOrderCustomer, bo.getJdOtherOutWarehouseOrderCustomerList());

        lqw.eq(bo.getNewOrderDate() != null, JdOtherOutWarehouseOrder::getNewOrderDate, bo.getNewOrderDate());
        lqw.eq(bo.getActualDeliveryNumber() != null, JdOtherOutWarehouseOrder::getActualDeliveryNumber, bo.getActualDeliveryNumber());
        if (params.get("beginTime") != null && params.get("endTime") != null) {
            lqw.between(JdOtherOutWarehouseOrder::getNewOrderDate,
                params.get("beginTime"),
                params.get("endTime"));
        }
        lqw.eq(StringUtils.isNotBlank(bo.getJdOtherOutWarehouseOrderStatus()), JdOtherOutWarehouseOrder::getJdOtherOutWarehouseOrderStatus, "已审核");
        // 返回构建好的查询包装器
        return lqw;
    }


    /**
     * 查询金蝶-其他出库单列表
     * 场景分类：部门领料-展销样品店铺
     * 业务查询条件：根据jd_other_out_warehouse_order_customer客户为展销样品店铺查询
     *
     * @param bo
     * @param pageQuery
     */
    @Override
    public TableDataInfo<JdOtherOutWarehouseOrderVo> queryPageListByCustomer2(JdOtherOutWarehouseOrderBo bo, PageQuery pageQuery) {
        LambdaQueryWrapper<JdOtherOutWarehouseOrder> lqw = buildQueryWrapperByCustomer2(bo);
        Page<JdOtherOutWarehouseOrderVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
        return TableDataInfo.build(result);
    }

    /**
     * 构建查询包装器
     * 场景分类：部门领料-展销样品店铺
     * 业务查询条件：根据jd_other_out_warehouse_order_customer客户为展销样品店铺查询
     *
     * @param bo 业务对象，包含查询参数
     * @return LambdaQueryWrapper 查询包装器
     */
    private LambdaQueryWrapper<JdOtherOutWarehouseOrder> buildQueryWrapperByCustomer2(JdOtherOutWarehouseOrderBo bo) {
        // 获取查询参数中的自定义参数
        Map<String, Object> params = bo.getParams();

        // 创建LambdaQueryWrapper实例，用于组装查询条件
        LambdaQueryWrapper<JdOtherOutWarehouseOrder> lqw = Wrappers.lambdaQuery();

        // 添加库存方向的精确查询条件
        lqw.eq(StringUtils.isNotBlank(bo.getInventoryDirection()), JdOtherOutWarehouseOrder::getInventoryDirection, bo.getInventoryDirection());

        // 添加订单状态的精确查询条件
        lqw.eq(StringUtils.isNotBlank(bo.getJdOtherOutWarehouseOrderStatus()), JdOtherOutWarehouseOrder::getJdOtherOutWarehouseOrderStatus, bo.getJdOtherOutWarehouseOrderStatus());

        // 添加订单号的精确查询条件
        lqw.eq(StringUtils.isNotBlank(bo.getJdOtherOutWarehouseOrderNumber()), JdOtherOutWarehouseOrder::getJdOtherOutWarehouseOrderNumber, bo.getJdOtherOutWarehouseOrderNumber());

        // 添加客户名称的精确查询条件
        lqw.eq(StringUtils.isNotBlank(bo.getJdOtherOutWarehouseOrderCustomer()), JdOtherOutWarehouseOrder::getJdOtherOutWarehouseOrderCustomer, bo.getJdOtherOutWarehouseOrderCustomer());

        // 添加物料编码的精确查询条件
        lqw.eq(StringUtils.isNotBlank(bo.getMaterialCode()), JdOtherOutWarehouseOrder::getMaterialCode, bo.getMaterialCode());

        // 添加物料名称的模糊查询条件
        lqw.like(StringUtils.isNotBlank(bo.getMaterialName()), JdOtherOutWarehouseOrder::getMaterialName, bo.getMaterialName());

        // 添加单位名称的模糊查询条件
        lqw.like(StringUtils.isNotBlank(bo.getUnitName()), JdOtherOutWarehouseOrder::getUnitName, bo.getUnitName());

        // 添加发货仓库的精确查询条件
        lqw.eq(StringUtils.isNotBlank(bo.getDeliverGoodsWarehouse()), JdOtherOutWarehouseOrder::getDeliverGoodsWarehouse, bo.getDeliverGoodsWarehouse());

        // 客户
        lqw.in(CollUtil.isNotEmpty(bo.getJdOtherOutWarehouseOrderCustomerList()), JdOtherOutWarehouseOrder::getJdOtherOutWarehouseOrderCustomer, bo.getJdOtherOutWarehouseOrderCustomerList());
        lqw.eq(bo.getNewOrderDate() != null, JdOtherOutWarehouseOrder::getNewOrderDate, bo.getNewOrderDate());
        lqw.eq(bo.getActualDeliveryNumber() != null, JdOtherOutWarehouseOrder::getActualDeliveryNumber, bo.getActualDeliveryNumber());
        if (params.get("beginTime") != null && params.get("endTime") != null) {
            lqw.between(JdOtherOutWarehouseOrder::getNewOrderDate,
                params.get("beginTime"),
                params.get("endTime"));
        }
        lqw.eq(StringUtils.isNotBlank(bo.getJdOtherOutWarehouseOrderStatus()), JdOtherOutWarehouseOrder::getJdOtherOutWarehouseOrderStatus, "已审核");
        // 返回构建好的查询包装器
        return lqw;
    }

    /**
     * 查询金蝶-其他出库单列表
     * 场景分类：部门领料-办公店铺
     * 业务查询条件：根据jd_other_out_warehouse_order_customer客户为办公店铺查询
     *
     * @param bo
     * @param pageQuery
     */
    @Override
    public TableDataInfo<JdOtherOutWarehouseOrderVo> queryPageListByCustomer3(JdOtherOutWarehouseOrderBo bo, PageQuery pageQuery) {
        LambdaQueryWrapper<JdOtherOutWarehouseOrder> lqw = buildQueryWrapperByCustomer3(bo);
        Page<JdOtherOutWarehouseOrderVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
        return TableDataInfo.build(result);
    }

    /**
     * 构建查询包装器
     * 场景分类：部门领料-办公店铺
     * 业务查询条件：根据jd_other_out_warehouse_order_customer客户为办公店铺查询
     *
     * @param bo 业务对象，包含查询参数
     * @return LambdaQueryWrapper 查询包装器
     */
    private LambdaQueryWrapper<JdOtherOutWarehouseOrder> buildQueryWrapperByCustomer3(JdOtherOutWarehouseOrderBo bo) {
        // 获取查询参数中的自定义参数
        Map<String, Object> params = bo.getParams();

        // 创建LambdaQueryWrapper实例，用于组装查询条件
        LambdaQueryWrapper<JdOtherOutWarehouseOrder> lqw = Wrappers.lambdaQuery();

        // 添加库存方向的精确查询条件
        lqw.eq(StringUtils.isNotBlank(bo.getInventoryDirection()), JdOtherOutWarehouseOrder::getInventoryDirection, bo.getInventoryDirection());

        // 添加订单状态的精确查询条件
        lqw.eq(StringUtils.isNotBlank(bo.getJdOtherOutWarehouseOrderStatus()), JdOtherOutWarehouseOrder::getJdOtherOutWarehouseOrderStatus, bo.getJdOtherOutWarehouseOrderStatus());

        // 添加订单号的精确查询条件
        lqw.eq(StringUtils.isNotBlank(bo.getJdOtherOutWarehouseOrderNumber()), JdOtherOutWarehouseOrder::getJdOtherOutWarehouseOrderNumber, bo.getJdOtherOutWarehouseOrderNumber());

        // 添加客户名称的精确查询条件
        lqw.eq(StringUtils.isNotBlank(bo.getJdOtherOutWarehouseOrderCustomer()), JdOtherOutWarehouseOrder::getJdOtherOutWarehouseOrderCustomer, bo.getJdOtherOutWarehouseOrderCustomer());

        // 添加物料编码的精确查询条件
        lqw.eq(StringUtils.isNotBlank(bo.getMaterialCode()), JdOtherOutWarehouseOrder::getMaterialCode, bo.getMaterialCode());

        // 添加物料名称的模糊查询条件
        lqw.like(StringUtils.isNotBlank(bo.getMaterialName()), JdOtherOutWarehouseOrder::getMaterialName, bo.getMaterialName());

        // 添加单位名称的模糊查询条件
        lqw.like(StringUtils.isNotBlank(bo.getUnitName()), JdOtherOutWarehouseOrder::getUnitName, bo.getUnitName());

        // 添加发货仓库的精确查询条件
        lqw.eq(StringUtils.isNotBlank(bo.getDeliverGoodsWarehouse()), JdOtherOutWarehouseOrder::getDeliverGoodsWarehouse, bo.getDeliverGoodsWarehouse());

        // 客户
        lqw.in(CollUtil.isNotEmpty(bo.getJdOtherOutWarehouseOrderCustomerList()), JdOtherOutWarehouseOrder::getJdOtherOutWarehouseOrderCustomer, bo.getJdOtherOutWarehouseOrderCustomerList());
        lqw.eq(bo.getNewOrderDate() != null, JdOtherOutWarehouseOrder::getNewOrderDate, bo.getNewOrderDate());
        lqw.eq(bo.getActualDeliveryNumber() != null, JdOtherOutWarehouseOrder::getActualDeliveryNumber, bo.getActualDeliveryNumber());
        if (params.get("beginTime") != null && params.get("endTime") != null) {
            lqw.between(JdOtherOutWarehouseOrder::getNewOrderDate,
                params.get("beginTime"),
                params.get("endTime"));
        }
        lqw.eq(StringUtils.isNotBlank(bo.getJdOtherOutWarehouseOrderStatus()), JdOtherOutWarehouseOrder::getJdOtherOutWarehouseOrderStatus, "已审核");
        // 返回构建好的查询包装器
        return lqw;
    }

    /**
     * 查询金蝶-其他出库单列表
     * 场景分类：部门领料-研发店铺
     * 业务查询条件：根据jd_other_out_warehouse_order_customer客户为研发店铺查询
     *
     * @param bo
     * @param pageQuery
     */
    @Override
    public TableDataInfo<JdOtherOutWarehouseOrderVo> queryPageListByCustomer4(JdOtherOutWarehouseOrderBo bo, PageQuery pageQuery) {
        LambdaQueryWrapper<JdOtherOutWarehouseOrder> lqw = buildQueryWrapperByCustomer4(bo);
        Page<JdOtherOutWarehouseOrderVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
        return TableDataInfo.build(result);
    }

    /**
     * 构建查询包装器
     * 场景分类：部门领料-研发店铺
     * 业务查询条件：根据jd_other_out_warehouse_order_customer客户为研发店铺查询
     *
     * @param bo 业务对象，包含查询参数
     * @return LambdaQueryWrapper 查询包装器
     */
    private LambdaQueryWrapper<JdOtherOutWarehouseOrder> buildQueryWrapperByCustomer4(JdOtherOutWarehouseOrderBo bo) {
        // 获取查询参数中的自定义参数
        Map<String, Object> params = bo.getParams();

        // 创建LambdaQueryWrapper实例，用于组装查询条件
        LambdaQueryWrapper<JdOtherOutWarehouseOrder> lqw = Wrappers.lambdaQuery();

        // 添加库存方向的精确查询条件
        lqw.eq(StringUtils.isNotBlank(bo.getInventoryDirection()), JdOtherOutWarehouseOrder::getInventoryDirection, bo.getInventoryDirection());

        // 添加订单状态的精确查询条件
        lqw.eq(StringUtils.isNotBlank(bo.getJdOtherOutWarehouseOrderStatus()), JdOtherOutWarehouseOrder::getJdOtherOutWarehouseOrderStatus, bo.getJdOtherOutWarehouseOrderStatus());

        // 添加订单号的精确查询条件
        lqw.eq(StringUtils.isNotBlank(bo.getJdOtherOutWarehouseOrderNumber()), JdOtherOutWarehouseOrder::getJdOtherOutWarehouseOrderNumber, bo.getJdOtherOutWarehouseOrderNumber());

        // 添加客户名称的精确查询条件
        lqw.eq(StringUtils.isNotBlank(bo.getJdOtherOutWarehouseOrderCustomer()), JdOtherOutWarehouseOrder::getJdOtherOutWarehouseOrderCustomer, bo.getJdOtherOutWarehouseOrderCustomer());

        // 添加物料编码的精确查询条件
        lqw.eq(StringUtils.isNotBlank(bo.getMaterialCode()), JdOtherOutWarehouseOrder::getMaterialCode, bo.getMaterialCode());

        // 添加物料名称的模糊查询条件
        lqw.like(StringUtils.isNotBlank(bo.getMaterialName()), JdOtherOutWarehouseOrder::getMaterialName, bo.getMaterialName());

        // 添加单位名称的模糊查询条件
        lqw.like(StringUtils.isNotBlank(bo.getUnitName()), JdOtherOutWarehouseOrder::getUnitName, bo.getUnitName());

        // 添加发货仓库的精确查询条件
        lqw.eq(StringUtils.isNotBlank(bo.getDeliverGoodsWarehouse()), JdOtherOutWarehouseOrder::getDeliverGoodsWarehouse, bo.getDeliverGoodsWarehouse());

        // 客户
        lqw.in(CollUtil.isNotEmpty(bo.getJdOtherOutWarehouseOrderCustomerList()), JdOtherOutWarehouseOrder::getJdOtherOutWarehouseOrderCustomer, bo.getJdOtherOutWarehouseOrderCustomerList());
        lqw.eq(bo.getNewOrderDate() != null, JdOtherOutWarehouseOrder::getNewOrderDate, bo.getNewOrderDate());
        lqw.eq(bo.getActualDeliveryNumber() != null, JdOtherOutWarehouseOrder::getActualDeliveryNumber, bo.getActualDeliveryNumber());
        if (params.get("beginTime") != null && params.get("endTime") != null) {
            lqw.between(JdOtherOutWarehouseOrder::getNewOrderDate,
                params.get("beginTime"),
                params.get("endTime"));
        }
        lqw.eq(StringUtils.isNotBlank(bo.getJdOtherOutWarehouseOrderStatus()), JdOtherOutWarehouseOrder::getJdOtherOutWarehouseOrderStatus, "已审核");
        // 返回构建好的查询包装器
        return lqw;
    }

    /**
     * 查询金蝶-其他出库单列表
     * 场景分类：其他出库-报废，盘亏
     * 业务查询条件：根据jd_other_out_warehouse_order_number单据编号为QT结尾的查询
     *
     * @param bo
     * @param pageQuery
     */
    @Override
    public TableDataInfo<JdOtherOutWarehouseOrderVo> queryPageListByOrderNumber(JdOtherOutWarehouseOrderBo bo, PageQuery pageQuery) {
        LambdaQueryWrapper<JdOtherOutWarehouseOrder> lqw = buildQueryWrapperByOrderNumber(bo);
        Page<JdOtherOutWarehouseOrderVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
        return TableDataInfo.build(result);
    }


    /**
     * 构建查询包装器
     * 场景分类：部门领料-研发店铺
     * 业务查询条件：根据jd_other_out_warehouse_order_customer客户为研发店铺查询
     *
     * @param bo 业务对象，包含查询参数
     * @return LambdaQueryWrapper 查询包装器
     */
    private LambdaQueryWrapper<JdOtherOutWarehouseOrder> buildQueryWrapperByOrderNumber(JdOtherOutWarehouseOrderBo bo) {
        // 获取查询参数中的自定义参数
        Map<String, Object> params = bo.getParams();

        // 创建LambdaQueryWrapper实例，用于组装查询条件
        LambdaQueryWrapper<JdOtherOutWarehouseOrder> lqw = Wrappers.lambdaQuery();

        // 添加库存方向的精确查询条件
        lqw.eq(StringUtils.isNotBlank(bo.getInventoryDirection()), JdOtherOutWarehouseOrder::getInventoryDirection, bo.getInventoryDirection());

        // 添加订单状态的精确查询条件
        lqw.eq(StringUtils.isNotBlank(bo.getJdOtherOutWarehouseOrderStatus()), JdOtherOutWarehouseOrder::getJdOtherOutWarehouseOrderStatus, bo.getJdOtherOutWarehouseOrderStatus());

        // 添加订单号的精确查询条件
        lqw.eq(StringUtils.isNotBlank(bo.getJdOtherOutWarehouseOrderNumber()), JdOtherOutWarehouseOrder::getJdOtherOutWarehouseOrderNumber, bo.getJdOtherOutWarehouseOrderNumber());

        // 添加客户名称的精确查询条件
        lqw.eq(StringUtils.isNotBlank(bo.getJdOtherOutWarehouseOrderCustomer()), JdOtherOutWarehouseOrder::getJdOtherOutWarehouseOrderCustomer, bo.getJdOtherOutWarehouseOrderCustomer());

        // 添加物料编码的精确查询条件
        lqw.eq(StringUtils.isNotBlank(bo.getMaterialCode()), JdOtherOutWarehouseOrder::getMaterialCode, bo.getMaterialCode());

        // 添加物料名称的模糊查询条件
        lqw.like(StringUtils.isNotBlank(bo.getMaterialName()), JdOtherOutWarehouseOrder::getMaterialName, bo.getMaterialName());

        // 添加单位名称的模糊查询条件
        lqw.like(StringUtils.isNotBlank(bo.getUnitName()), JdOtherOutWarehouseOrder::getUnitName, bo.getUnitName());

        // 添加发货仓库的精确查询条件
        lqw.eq(StringUtils.isNotBlank(bo.getDeliverGoodsWarehouse()), JdOtherOutWarehouseOrder::getDeliverGoodsWarehouse, bo.getDeliverGoodsWarehouse());

        // 单据编号
        lqw.like(StringUtils.isNotBlank(bo.getJdOtherOutWarehouseOrderNumber()), JdOtherOutWarehouseOrder::getJdOtherOutWarehouseOrderNumber, "%" + bo.getJdOtherOutWarehouseOrderNumber() + "QT");
        lqw.eq(bo.getNewOrderDate() != null, JdOtherOutWarehouseOrder::getNewOrderDate, bo.getNewOrderDate());
        lqw.eq(bo.getActualDeliveryNumber() != null, JdOtherOutWarehouseOrder::getActualDeliveryNumber, bo.getActualDeliveryNumber());
        if (params.get("beginTime") != null && params.get("endTime") != null) {
            lqw.between(JdOtherOutWarehouseOrder::getNewOrderDate,
                params.get("beginTime"),
                params.get("endTime"));
        }
        lqw.eq(StringUtils.isNotBlank(bo.getJdOtherOutWarehouseOrderStatus()), JdOtherOutWarehouseOrder::getJdOtherOutWarehouseOrderStatus, "已审核");
        // 返回构建好的查询包装器
        return lqw;
    }



}
